package cn.iocoder.yudao.module.written.exam.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.util.StringUtils;

import java.util.Objects;

@Getter
@AllArgsConstructor
public enum QuestionTypeEnum {

    SINGLE_CHOICE(1, "单选题", 1d),
    MULTIPLE_CHOICE(2, "多选题", 1.5d),
    SHORT_ANSWER(3, "简答题", 5d),
    PROGRAM_QUESTION(4, "编程题", 7.5d),
//    JUDGMENT(4, "判断题"),
//    FILL_IN_THE_BLANK(5, "填空题"),
//

    ;

    private Integer code;
    private String desc;
    // 题型的价格系数
    private double coefficient;

    public static QuestionTypeEnum getByCode(Integer code) {
        if (Objects.isNull(code)) {
            return null;
        }
        for (QuestionTypeEnum value : values()) {
            if (value.code.equals(code)) {
                return value;
            }
        }
        return null;
    }

    public static QuestionTypeEnum getByDesc(String desc) {
        if (StringUtils.isEmpty(desc)) {
            return null;
        }
        for (QuestionTypeEnum value : values()) {
            if (value.desc.equals(desc)) {
                return value;
            }
        }
        return null;
    }

}
